﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using WebApi1000.Model.Entity;

namespace WebApi1000.Model
{
    public class DbInitializeHelper
    {
        public static void Initilzer()
        {
            using (var db = new Admin1000Context())
            {
                var dbExist = db.Database.EnsureCreated();
                var add = db.Classes.Any();
                if (!add)
                {
                    var clas = new Class
                    {
                        ClassName = "计应四班"
                    };
                    db.Classes.Add(clas);
                    db.SaveChanges();

                    db.Teachers.AddRange(new Teacher[]
                    {
                    new Teacher
                    {
                        TeacherName="老胡",
                        TeacherSex="男",
                        ClassId=clas.Id
                    }
                    });
                    db.SaveChanges();

                    db.Students.AddRange(new Student[]
                    {
                    new Student
                    {
                        StudentName="aaa",
                        StudentSex="男",
                        ClassId=clas.Id
                    },
                    new Student
                    {
                        StudentName="bbb",
                        StudentSex="女",
                        ClassId=clas.Id
                    }
                    });
                    db.SaveChanges();
                }
            }
        }
    }
}
